<?php
namespace ClubAdmin\Controller;
use Think\Controller;
class ClubController extends Controller {

public function quality(){
  $list=M('course');
  $list2=M('coach');
  $listmodel=$list->join(" __COACH__  ON __COURSE__.coach_id =__COACH__.coach_id ")
->select();
  $this->list=$listmodel;

 $this->display();
      
 }


 public function club(){
  $id=session('cadmin_id');
  // dump($id);die();
  $listmodel=M('club');
  
  $this->list=$listmodel->order('club_id desc')->select();
  // dump($list);die();

  $this->display();
      
 }

 
public function clubdelete($id){
  $clubModel= M('club');
  if (false!==$clubModel->where("club_id=$id")->delete()) {
          $this->success('删除成功！');
      } else {
          $this->error('删除失败');
      }
}

  public function qx($id){
        $coursemodel=M('course');
        $coursemodel->course_flag="0";
        if(false!==$coursemodel->where("course_id=$id")->save()){
                redirect(U("Club/quality"));
        }else{
                $this->error('取消失败！');
        }
 }


public function jp($id){
        $coursemodel=M('course');
        $coursemodel->course_flag="1";
        if(false!==$coursemodel->where("course_id=$id")->save()){
                redirect(U("Club/quality"));
        }else{
                $this->error('添加精品失败！');
        }
 }

public function video(){
  $list=M('video');
  $listmodel=$list->order('video_id desc')->select();
  $this->list=$listmodel;

 $this->display();
 }

public function videodelete($video_id){
    $videomodel= M('video');
    $video=$videomodel->where("video_id=$video_id")->find();
          if ($video["video_pic"]=="default.jpg") 
        {

        }
            else
        {
                unlink(realpath("./Public/pic/".$video["video_pic"]));
        }

    if (false!==$videomodel->where("video_id=$video_id")->delete()) {
            $this->success('删除成功！');
        } else {
            $this->error('删除失败');
        }
    }


 public function videochange($id){
  session('video_id',$id);
  $this->display();
 }
   public function updatavideo()
    {
        $videomodel = M('video');
        $id = I('session.video_id');
        $data['video_name'] = I('post.name');
        if ($_FILES['file']['error'] == 0) {
            $picinfo = $this->upload();
            $pname = $picinfo['file']['savename'];
        } else {
            $pname = "default.jpg";
        }
        if ($_FILES['other']['error'] == 0) {
            $mvinfo = $this->upvideo();
            $mname = $mvinfo['other']['savename'];
        } else {
            $mname = "default.mp3";
        }
        $data['video_pic'] = $pname;
        $data['video_mv'] = $mname;
        if (false !== $videomodel->where("video_id = $id")->save($data)) {
            $this->success('修改成功', 'video');
        } else {
            $this->error('修改失败');
        }
    }


public function clubchange(){
  $id=I('get.id');
  // dump($id);die();
   $this->change=M("club")->where("club_id=$id")->find();
  $this->display();
}
 public function updataclub(){
   
   $clubmodel = M("club");
   $id['club_id'] = I('post.club_id');
   
   $data['club_id'] = I('post.club_id');
   $data['club_name'] = I('post.club_name');
   $data['club_address'] = I('post.club_address');
   $data['club_date'] = date('Y-m-d H:i:s');
   $data['club_explain'] = I('post.club_explain');
   $data['cadmin_id'] = I('post.cadmin_id');
   if ($_FILES['file']['error'] == 0) {
            $logoinfo = $this->upload();
            $pname = $logoinfo['file']['savename'];
        } else {
            $pname = "default.jpg";
        }
        $data['club_pic'] = $pname;
   
   if (false !== $clubmodel->where($id)->save($data)) {
     $this->success('修改成功','club');
  }else{
    $this->error('修改失败');
  }      
 }


public function addclub(){
   
   $clubmodel = M("club");
   $data['club_id'] = I('post.club_id');
   $data['club_name'] = I('post.club_name');
   $data['club_address'] = I('post.club_address');
   $data['club_date'] = date('Y-m-d H:i:s');
   $data['club_explain'] = I('post.club_explain');
   $data['cadmin_id'] = session('cadmin_id');

   if ($_FILES['file']['error'] == 0) {
            $logoinfo = $this->upload();
            $pname = $logoinfo['file']['savename'];
        } else {
            $pname = "default.jpg";
        }
        $data['club_pic'] = $pname;
   
   if (false !== $clubmodel->add($data)) {
     $this->success('添加成功','club');
  }else{
    $this->error('添加失败');
  }      
 }

public function addvideo(){
   
   $videomodel = M("video");
   // dump($videomodel);die();
   $data['video_id'] = I('post.video_id');
   $data['video_name'] = I('post.video_name');
   $data['video_mv'] = I('post.video_mv');
   $data['club_id'] = I('post.club_id');
   $data['video_publisher'] = session('cadmin_id');
   $data['video_hit']=0;
   $data['video_date'] = date('Y-m-d H:i:s');
   if ($_FILES['file']['error'] == 0) {
            $logoinfo = $this->upload();
            $pname = $logoinfo['file']['savename'];
        } else {
            $pname = "default.jpg";
        }

        $data['video_pic'] = $pname;

   
   if (false !== $videomodel->add($data)) {
     $this->success('添加成功','video');
  }else{
    $this->error('添加失败');
  }      
 }

 public function upload(){

       $upload = new \Think\Upload();// 实例化上传类
       $upload->maxSize=3145728 ;// 设置附件上传大小
       $upload->exts=array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
       $upload->rootPath='./Public/pic/'; // 设置附件上传根目录
        $upload->autoSub=false; 
       // $upload->savePath  =''; // 设置附件上传（子）目录
       $info =$upload->upload();  // 上传文件 
       // dump()
        $data=$info["pic"]["savename"];
      
        
       if(!$info) {  
             // $this->error($upload->getError());   
           }else{       
               // $this->success('上传成功！');   
             return $info;
              }              
        }

public function upvideo(){

       $upload = new \Think\Upload();// 实例化上传类
       $upload->maxSize=3145728 ;// 设置附件上传大小
       $upload->exts=array('mp3', 'wmv', 'avi', 'rm', 'rmvb');// 设置附件上传类型
       $upload->rootPath='./Public/pic/'; // 设置附件上传根目录
        $upload->autoSub=false; 
       // $upload->savePath  =''; // 设置附件上传（子）目录
       $info =$upload->upload();  // 上传文件 
       // dump()
        $data=$info["mv"]["savename"];
      
        
       if(!$info) {  
             // $this->error($upload->getError());   
           }else{       
               // $this->success('上传成功！');   
             return $info;
              }              
        }

//亲爱的 2017/8/31 15:56:08
//修改比赛信息
 public function club_update(){
        
             // $id=session('adminid');
        // dump($uid);exit;
       $pic=I('post.club_logo');
         // dump($pic);exit;

       $clubmodel =M('club');
    
         if ($clubmodel->create()) {
           if($_FILES["pic"]["error"]==0){
             $info=$this->upload();

             if($pic!='default.jpg'){
                unlink(realpath("./Public/pic/".$pic));
             }
             $club_logo=$info["pic"]["savename"];
             // dump($club_logo);die();exit;
           }

             // $clubmodel->creatime=date('Y-m-d H:i:s');

             if (false !== $clubmodel->save()) {
               redirect(U("index.php/ClubAdmin/Club/club"));
               }else{         
                   $this->error('数据错误');        
                    }
               }else{
                   $this->error($clubmodel->getError());
                    }
 }










// public function videodelete($video_id){
//     $videomodel= M('video');
//     $video=$videomodel->where("video_id=$video_id")->find();
//           if ($video["video_pic"]=="default.jpg") 
//         {

//         }
//             else
//         {
//                 unlink(realpath("./Public/pic/".$video["video_pic"]));
//         }

//     if (false!==$videomodel->where("video_id=$video_id")->delete()) {
//             $this->success('删除成功！');
//         } else {
//             $this->error('删除失败');
//         }
//     }


 }
